
package com.focusai.efairy.ui.widget;

import android.content.Context;
import android.widget.TextView;

import com.focusai.efairy.R;
import com.focusai.efairy.utils.DecimalUtils;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;


/**
 * Custom implementation of the MarkerView.
 * <p>
 * Created by AlysaLee on 2017/4/5.
 */
public class LineMarkerView extends MarkerView {

    private TextView textView;

    public LineMarkerView(Context context, int layoutResource) {
        super(context, layoutResource);

        textView = (TextView) findViewById(R.id.txt_marker);
    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        if (e instanceof CandleEntry) {
            CandleEntry ce = (CandleEntry) e;
            textView.setText(DecimalUtils.formatNum2(ce.getHigh()));
        } else {
            textView.setText(DecimalUtils.formatNum2(e.getY()));
        }
        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight() + Utils.convertDpToPixel(3.5f));
    }
}
